const app = getApp();
const { AskComponent } = app._require("common/index");
AskComponent({
    properties: {
        fixed: {
            type: Boolean,
            optionalTypes: [String],
            value: false,
        },
        hasHeader: {
            type: Boolean,
            value: true,
        },
        hasFooter: {
            type: Boolean,
            value: true,
        },
        customClass: {
            type: String,
            value: "",
        },
    },
    data: {
        statusBar: app.globalData.StatusBar,
        customBar: app.globalData.CustomBar,
        isCustomBar: false,
        totalShow: false,
        authShow: false,
    },
    methods: {
        toggleNum() {
            this.$emit("fixed-change", { type: "num" });
            this.setData({
                totalShow: !this.data.totalShow,
            });
        },
        backTop() {
            wx.pageScrollTo({
                scrollTop: 0,
                duration: 300,
            });
            this.$emit("fixed-change", { type: "top" });
        },
        openAuth() {
            const _page = this.getPage();
            const whiteList = ["pages/personal/index"];
            this.setData({
                authShow: true,
                isCustomBar: _page ? whiteList.includes(_page.route) : false,
            });
        },
        onClose() {
            this.setData({
                authShow: false,
            });
        },
        login() {
            const _page = this.getPage();
            wx.navigateTo({
                url: `/pages/login/index?url=${(_page && _page.route) || ""}`,
                success: () => {
                    this.onClose();
                },
                events: {
                    // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
                    sure: data => {
                        setTimeout(() => {
                            const _page = this.getPage();
                            if (_page && _page.loginSuccess) {
                                _page.loginSuccess();
                            }
                        }, 100);
                    },
                },
            });
        },
    },
});
